package cn.wizzer.app.web.modules.controllers.match;

import cn.wizzer.app.match.modules.models.constant.Fields;
import cn.wizzer.app.match.modules.services.MatchService;
import cn.wizzer.app.sys.modules.models.SysDict;
import cn.wizzer.app.sys.modules.services.SysDictService;
import cn.wizzer.app.user.modules.models.vo.MatchLives;
import cn.wizzer.framework.base.Result;
import cn.wizzer.framework.page.Pagination;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

/**
 * pc端页面比赛信息
 */
@At("/api/match")
@IocBean
public class ApiMatchController {

    @Reference
    @Inject
    private MatchService matchService;


    @Reference
    @Inject
    private SysDictService sysDictService;

    /**
     * 第一分类及其数据
     *
     * @return
     */
    @At("/listOfFirstCategory")
    @Ok("json")
    public Result categoryList() {
        SysDict matchCategory = sysDictService.getSortedSubsListByCode(Fields.MATCH_CATEGORY).get(0);
        Pagination pagination = matchService.listByCode(matchCategory.getCode(), null, null, 0, 8);
        return Result.success().addData(new NutMap().addv("category",matchCategory).addv("data",pagination.getList()));
    }


    /**
     * 根据分类信息查询赛事信息
     *
     * @param code
     * @return
     */
    @At()
    @Ok("json:full")
    public Result listByCode(@Param("code") String code, @Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("pageNumber") int pageNumber, @Param("pageSize") int pageSize) {
        Pagination pagination = matchService.listByCode(code, startTime, endTime, pageNumber, pageSize);
        return Result.success(pagination);
    }
    /**
     * 根据ID查询赛事信息
     *
     * @param id
     * @return
     */
    @At()
    @Ok("json:full")
    public Result getMatchById(@Param("id") String id) {
        MatchLives lives = matchService.hget(id);
        return Result.success(lives);
    }

}





